package core.form.election;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class WzdPgAddEditVotingCardOption extends WizardPage {
//	private DataBindingContext m_bindingContext;
//	
//	public DataBindingContext getBindingContext() {
//		return m_bindingContext;
//	}
	
	private boolean addVotingCardOption;
	private VotingCardOption votingCardOption;
	
	private Text nameText;
	
	/**
	 * Create the wizard.
	 * 
	 * @param votingCard
	 * @param addVotingCard
	 */
	public WzdPgAddEditVotingCardOption(boolean addVotingCardOption, VotingCardOption votingCardOption) {
		super("WzdPgAddEditVotingCardOption");
		if (addVotingCardOption) {
			setTitle("Add Voting Card Option");
			setDescription("Add new Voting Card Option to the Voting Card.");
		} else {
			setTitle("Edit Voting Card Option");
			setDescription("Edit an existing Voting Card Option of the Voting Card.");
		}
		
		this.addVotingCardOption = addVotingCardOption;
		this.votingCardOption = votingCardOption;
	}

	/**
	 * Create contents of the wizard.
	 * 
	 * @param parent
	 */
	public void createControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NULL);

		setControl(container);

		container.setLayout(new GridLayout(2, false));

		new Label(container, SWT.NONE).setText("Name:");

		nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
		nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

//		if (votingCardOption != null) {
//			m_bindingContext = initDataBindings();
//		}
//		WizardPageSupport.create(this, m_bindingContext);
	}
	
	/*private DataBindingContext initDataBindings() {
		final IObservableValue nameObserveWidget = SWTObservables.observeText(nameText, SWT.Modify);
		IObservableValue nameObserveValue = PojoObservables.observeValue(votingCardOption, "name");
		//
		DataBindingContext bindingContext = new DataBindingContext();
		//
		bindingContext.bindValue(nameObserveWidget, nameObserveValue, null, null);
		//
		
		MultiValidator multiValidator = new MultiValidator() {
			protected IStatus validate() {
				String name = (String) nameObserveWidget.getValue();

				// error
				if (name.trim().length() == 0) {
					return ValidationStatus.error("Name cannot be empty.");
				}
				// ok
				return ValidationStatus.ok();
			}
		};

		bindingContext.addValidationStatusProvider(multiValidator);
		return bindingContext;
	}*/

	public core.form.election.VotingCardOption getVotingCardOption() {
		return votingCardOption;
	}

	public void setVotingCardOption(core.form.election.VotingCardOption newVotingCardOption) {
		setVotingCardOption(newVotingCardOption, true);
	}

	public void setVotingCardOption(core.form.election.VotingCardOption newVotingCardOption, boolean update) {
		votingCardOption = newVotingCardOption;
		// if (update) {
		// if (m_bindingContext != null) {
		// m_bindingContext.dispose();
		// m_bindingContext = null;
		// }
		// if (votingCardOption != null) {
		// m_bindingContext = initDataBindings();
		// }
		// }
	}

}
